package it.uniroma2.art.owlart.langsearch.index;

import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.langsearch.index.config.IndexingConfiguration;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.vocabulary.RDFResourceRolesEnum;

import java.io.IOException;

/**
 * a simple facility extension to RDFIndexManager providing direct methods for addressing indexing of typical
 * owl resources (classes, properties, individuals)
 * 
 * @author Armando Stellato <a href="mailto:stellato@info.uniroma2.it">stellato@info.uniroma2.it</a>
 * 
 */
public class OWLIndexManager extends RDFIndexManager {

	public OWLIndexManager(OWLModel m, String IndexDir, IndexingConfiguration idxConfig) {
		super(m, IndexDir, idxConfig);
	}

	// INDEX MODIFICATION METHODS (rely on main methods from IndexManager, expanding them with specific
	// signatures for classes, properties, individuals

	// ADD

	public void addNewClassToIndex(ARTURIResource cls) throws IOException {
		addNewResourceToIndex(cls, RDFResourceRolesEnum.cls.toString());
	}

	public void addNewPropertyToIndex(ARTURIResource prop) throws IOException {
		addNewResourceToIndex(prop, RDFResourceRolesEnum.property.toString());
	}

	public void addNewIndividualToIndex(ARTURIResource ind) throws IOException {
		addNewResourceToIndex(ind, RDFResourceRolesEnum.individual.toString());
	}

	// DELETION

	/**
	 * to be invoked when a class is being removed from the managed ontology model. Both the URI, localname
	 * and all labels for each language are removed from the multilingual indexes
	 * 
	 * @param ontResource
	 * @param idxIdentifier
	 * @throws IOException
	 */
	public void deleteClassFromIndexes(ARTURIResource ontResource) throws IOException {
		deleteResourceFromIndexes(ontResource, RDFResourceRolesEnum.cls.toString());
	}

	/**
	 * to be invoked when a property is being removed from the managed ontology model. Both the URI, localname
	 * and all labels for each language are removed from the multilingual indexes
	 * 
	 * @param ontResource
	 * @param idxIdentifier
	 * @throws IOException
	 */
	public void deletePropertyFromIndexes(ARTURIResource ontResource) throws IOException {
		deleteResourceFromIndexes(ontResource, RDFResourceRolesEnum.property.toString());
	}

	/**
	 * to be invoked when an individual is being removed from the managed ontology model. Both the URI,
	 * localname and all labels for each language are removed from the multilingual indexes
	 * 
	 * @param ontResource
	 * @param idxIdentifier
	 * @throws IOException
	 */
	public void deleteIndividualFromIndexes(ARTURIResource ontResource) throws IOException {
		deleteResourceFromIndexes(ontResource, RDFResourceRolesEnum.individual.toString());
	}

	// UPDATE

	/**
	 * facility for {@link #updateLangIndexForResource(ARTURIResource, String, String)} which specifies
	 * {@link RDFResourceRolesEnum#cls} as the name of the index
	 * 
	 * @param ontResource
	 * @param lang
	 * @throws IOException
	 * @throws ModelAccessException
	 */
	public void updateLangIndexForClass(ARTURIResource ontResource, String lang) throws IOException,
			ModelAccessException {
		updateLangIndexForResource(ontResource, RDFResourceRolesEnum.cls.toString(), lang);
	}

	/**
	 * facility for {@link #updateLangIndexForResource(ARTURIResource, String, String)} which specifies
	 * {@link RDFResourceRolesEnum#property} as the name of the index
	 * 
	 * @param ontResource
	 * @param lang
	 * @throws IOException
	 * @throws ModelAccessException
	 */
	public void updateLangIndexForProperty(ARTURIResource ontResource, String lang) throws IOException,
			ModelAccessException {
		updateLangIndexForResource(ontResource, RDFResourceRolesEnum.property.toString(), lang);
	}

	/**
	 * facility for {@link #updateLangIndexForResource(ARTURIResource, String, String)} which specifies
	 * {@link RDFResourceRolesEnum#individual} as the name of the index
	 * 
	 * @param ontResource
	 * @param lang
	 * @throws IOException
	 * @throws ModelAccessException
	 */
	public void updateLangIndexForIndividual(ARTURIResource ontResource, String lang) throws IOException,
			ModelAccessException {
		updateLangIndexForResource(ontResource, RDFResourceRolesEnum.individual.toString(), lang);
	}

}
